package org.dyk.mallmanagementsystem.repository;

import org.dyk.mallmanagementsystem.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface UserRepository extends CrudRepository<User,Integer> {
    //查询所有用户信息，并分页
    public Page<User> findAll(Pageable pageable);

    //查询所有用户
    public List<User> findAll();

    //根据登录名获取用户信息
    public User findByUserLoginName(String userLoginName);

    //根据uid获取用户信息
    public User findByUid(int uid);

    //自定义查询用户
    @Query(nativeQuery = true, value = "select * from user where " +
            "if(?1 != '', user_login_name like %?1%, 1=1) " +
            "and if(?2 != '', user_name like %?2%, 1=1)")
    public List<User> selectUser(String loginName, String userName);
}
